package org.flexthinker.binding.conversion.support
{
    import org.hamcrest.assertThat;
    import org.hamcrest.object.equalTo;

    public class PropertyConverterTest
    {
        public var pc:PropertyConverter;

        public function PropertyConverterTest()
        {
        }

        [Test]
        public function testStringToIntConversion():void
        {
            pc = PropertyConverter.STRING_TO_INT_CONVERTER;

            assertThat(pc.convertForward("123") === 123, equalTo(true));
            assertThat(pc.convertForward("456.45") === 456, equalTo(true));
            assertThat(pc.convertForward(789) === 789, equalTo(true));

            assertThat(pc.convertReverse(-333) === "-333", equalTo(true));
            assertThat(pc.convertReverse("222") === "222", equalTo(true));
        }

        [Test]
        public function testStringToBooleanConverter():void
        {
            pc = PropertyConverter.STRING_TO_BOOLEAN_CONVERTER;

            assertThat(pc.convertForward("true"), equalTo(true));
            assertThat(pc.convertForward("True"), equalTo(true));
            assertThat(pc.convertForward("TRUE"), equalTo(true));
            assertThat(pc.convertForward("false"), equalTo(false));
            assertThat(pc.convertForward("False"), equalTo(false));
            assertThat(pc.convertForward("FALSE"), equalTo(false));

            assertThat(pc.convertReverse(true), equalTo("true"));
            assertThat(pc.convertReverse(false), equalTo("false"));
        }

        [Test]
        public function testStringToNumberConverter():void
        {
            pc = PropertyConverter.STRING_TO_NUMBER_CONVERTER;

            assertThat(pc.convertForward("123") === 123, equalTo(true));
            assertThat(pc.convertForward("-456.45") === -456.45, equalTo(true));
            assertThat(pc.convertForward(789) === 789, equalTo(true));

            assertThat(pc.convertReverse(333) === "333", equalTo(true));
            assertThat(pc.convertReverse("0222.44") === "222.44", equalTo(true));
        }

        [Test]
        public function testIntToStringConversion():void
        {
            pc = PropertyConverter.INT_TO_STRING_CONVERTER;

            assertThat(pc.convertForward(123) === "123", equalTo(true));
            assertThat(pc.convertForward("123") === "123", equalTo(true));

            assertThat(pc.convertReverse("456") === 456 , equalTo(true));
            assertThat(pc.convertReverse("456") === "456" , equalTo(false));
        }

        [Test]
        public function testNumberToStringConverter():void
        {
            pc = PropertyConverter.NUMBER_TO_STRING_CONVERTER;

            assertThat(pc.convertForward(333.33)=== "333.33", equalTo(true));
            assertThat(pc.convertReverse("444.44") === 444.44, equalTo(true));
        }

        [Test]
        public function testBooleanToStringConverter():void
        {
            pc = PropertyConverter.BOOLEAN_TO_STRING_CONVERTER;

            assertThat(pc.convertForward(true) === "true", equalTo(true));
            assertThat(pc.convertForward(false) === "false", equalTo(true));
            assertThat(pc.convertReverse("TRUE") === true, equalTo(true));
            assertThat(pc.convertReverse("false") === false, equalTo(true));
        }


    }
}
